﻿using System.IO;
using System.Text;

namespace SubRepair.ChangeEncoding
{
    class Convert1256ToUTF8 : ConvertToUTF8
    {

        public Convert1256ToUTF8()
            : base(1256)
        {
        }

        public override void Convert()
        {
            using (var read = new StreamReader(this.FileAddress, this.SourceEncoding, true))
            {
                this.SourceString = read.ReadToEnd();

                byte[] source = this.SourceEncoding.GetBytes(SourceString);
                byte[] dest = Encoding.Convert(this.SourceEncoding, Encoding.UTF8, source);

                char[] UTF8Chars = new char[Encoding.UTF8.GetCharCount(dest, 0, dest.Length)];
                Encoding.UTF8.GetChars(dest, 0, dest.Length, UTF8Chars, 0);

                this.FinalString = new string(UTF8Chars);
            }

            this.Save();
        }
    }
}
